package com.bdqn.Di3Zhan;

import net.sf.cglib.proxy.Enhancer;
import org.apache.log4j.Logger;


public class IntermediaryCglibProxyFactory {
    private static Logger log = Logger.getLogger(IntermediaryCglibProxyFactory.class);
    private static IntermediaryMethodInterceptor callback = new IntermediaryMethodInterceptor();

    public static <T> T create(Class<T> target){
        Enhancer enhancer = new Enhancer();

        enhancer.setCallback(callback);

        enhancer.setSuperclass(target);

        return (T)enhancer.create();
    }

    public void havealookCglibProxy()throws Exception{
        RealBuyer buyer = IntermediaryCglibProxyFactory.create(RealBuyer.class);
        String result = buyer.havealook();
        log.debug(result);
    }
}
